package com.smartwrite.enums;

/**
 * 任务状态枚举
 * 定义任务在生命周期中的各种状态
 */
public enum TaskStatus {
    PENDING("pending", "等待执行"),
    RUNNING("running", "正在执行"),
    COMPLETED("completed", "执行完成"),
    ERROR("error", "执行错误"),
    STOPPED("stopped", "手动停止");
    
    private final String code;
    private final String description;
    
    TaskStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 根据代码获取枚举值
     */
    public static TaskStatus fromCode(String code) {
        for (TaskStatus status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown task status code: " + code);
    }
    
    /**
     * 检查是否为终止状态
     */
    public boolean isTerminal() {
        return this == COMPLETED || this == ERROR || this == STOPPED;
    }
    
    /**
     * 检查是否为运行状态
     */
    public boolean isActive() {
        return this == PENDING || this == RUNNING;
    }
}